﻿@using System.Linq
@using DevExpress.Blazor.Internal
@using System.Collections.ObjectModel
@using System.Text

<DemoPageSectionComponent Id="Navigation-Accordion-DataBinding" VerticalAlignment=VerticalAlignment.Top MinHeight="296" ShowSizeMode="true">
    <ChildContentWithParameters Context="Params">
        @if(Data == null) {
            <p>
                <em>Loading...</em>
            </p>
        }
        else {
            <div class="cw-480">
                <DxAccordion Data="@Data"
                             SizeMode="Params.SizeMode"
                             ShowFilterPanel="true"
                             RootItemExpandButtonDisplayMode="AccordionExpandButtonDisplayMode.End"
                             SubItemExpandButtonIconCssClass="icon-square-plus"
                             SubItemCollapseButtonIconCssClass="icon-square-minus">
                    <DataMappings>
                        <DxAccordionDataMapping Text="Name"
                                                Key="Id"
                                                ParentKey="CategoryId"/>
                    </DataMappings>
                </DxAccordion>
            </div>
        }
    </ChildContentWithParameters>

    @code {
        List<FlatDataItem> Data { get; set; }
        protected override void OnInitialized() {
            IEnumerable<ProductFlat> products = ProductData.Products;
            IEnumerable<ProductCategory> productSubcategories = ProductData.Categories;
            Data = new List<FlatDataItem>(Enum.GetValues<ProductCategoryMain>().Select(i => new FlatDataItem() { Name = i.ToString(), Id = i }));
            Data.AddRange(products.Select(i => new FlatDataItem() { Name = i.ProductName, Id = i.Id, CategoryId = i.ProductCategoryId }));
            Data.AddRange(productSubcategories.Select(i => new FlatDataItem() { Name = i.Subcategory, Id = i.SubcategoryID, CategoryId = i.Category }));
        }
    }

</DemoPageSectionComponent>
